from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction import DictVectorizer
def data_demo():
    iris=load_iris()
    #print(iris)
    #print(iris['DESCR'])
    x_train, x_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=22)
    print("训练集特征值：\n", x_train, x_train.shape)
    print("测试集特征值：\n", x_test, x_test.shape)
def dict_demo():
    data = [
        {'color': '红', 'size': 10, 'shape': '圆形'},
        {'color': '蓝', 'size': 8, 'shape': '方形'},
        {'color': '红', 'size': 12, 'shape': '三角形'}
    ]
    transfer=DictVectorizer(sparse=False)
    new_data=transfer.fit_transform(data)
    print(new_data)
if __name__=="__main__":
    # data_demo()
    dict_demo()